package shop.services;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import shop.dao.GoodsDao;
import shop.pojo.Goods;
import shop.util.SqlSessionUtil;

public class GoodsServices {
	/*添加商品*/
	public int AddGoods(Goods goods){
		SqlSession se = new SqlSessionUtil().getSqlSession();
		GoodsDao gd = se.getMapper(GoodsDao.class);
		int i =gd.GoodsAddOne(goods);
		se.commit();
		return i;
	}
	/*查询商品*/
	public List<Goods> SelAllGoods(){
		SqlSession se = new SqlSessionUtil().getSqlSession();
		GoodsDao gd = se.getMapper(GoodsDao.class);
		List<Goods> list = gd.GoodsSel();
		return list;
	}
	/*查询当前页商品*/
	public List<Goods> SelCurrentGoods(int page){
		SqlSession se = new SqlSessionUtil().getSqlSession();
		GoodsDao gd = se.getMapper(GoodsDao.class);
		List<Goods> list = gd.GoodsSelPage(page);
		return list;
	}
	/*删除商品*/
	public void DelOneGoods(int id){
		SqlSession se = new SqlSessionUtil().getSqlSession();
		GoodsDao gd = se.getMapper(GoodsDao.class);
		gd.GoodsDel(id);
		se.commit();
	}
	/*查询某件商品*/
	public List<Goods> SelAllOneGoods(int g_id){
		SqlSession se = new SqlSessionUtil().getSqlSession();
		GoodsDao gd = se.getMapper(GoodsDao.class);
		List<Goods> list = gd.GoodsSelOne(g_id);
		return list;
	}
	/*修改某件商品*/
	public int UpdateOnewGoods(Goods goods){
		SqlSession se = new SqlSessionUtil().getSqlSession();
		GoodsDao gd = se.getMapper(GoodsDao.class);
		int i;
		i = gd.GoodsUpt(goods);
		se.commit();
		return i;
	}
}
